<style lang="scss">
	page{
		background: #F5F5F5;
		// padding-top: 30upx;
		.all{
			width: 750upx;
			margin-top: -20upx;
			.box{
				padding: 30upx;
				width: 690upx;
				background: #FFFFFF;
				display: flex;
				margin-top: 20upx;
				.box_image{
					width: 40upx;
					height: 40upx;
					margin-top: 44upx;
				}
				.box_images{
					width: 34upx;
					height: 36upx;
					margin-top: 48upx;
					margin-left: 50upx;
				}
				.box_text{
					margin-left: 42upx;
					width: 496upx;
					.box_text_name{
						width: 496upx;
						display: flex;
						.box_text_name_name{
							width: 330upx;
							height: 42upx;
							font-size: 30upx;
							font-weight: bold;
							color: #333333;
							line-height: 42upx;
						}
						.box_text_phone{
							height: 40upx;
							font-size: 28upx;
							font-weight: bold;
							color: #333333;
							line-height: 40upx;
						}
					}
					.box_text_address{
						width: 496upx;
						margin-top: 10upx;
						height: 68upx;
						font-size: 24upx;
						font-weight: 400;
						color: #999999;
						line-height: 34upx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						 display: -webkit-box;
						-webkit-line-clamp: 2;
						line-clamp: 2;
						-webkit-box-orient: vertical;
					}
				}
			}
			.anniu{
				width: 750upx;
				background: #1C336B;
				height: 100upx;
				text-align: center;
				line-height: 100upx;
				font-size: 32upx;
				color: #FFFFFF;
				position: fixed;
				bottom: 0;
			}
			.zanwu{
				width: 100%;
				line-height: 300upx;
				height: 300upx;
				color: #999999;
				font-size: 28upx;
				text-align: center;
			}
		}
	}
</style>
<template>
	<view class="all">
		<view style="padding-bottom: 120upx;">
			<view class="box" v-if="list.length != 0" v-for="(item,index) in list" :key="index" @click.stop="pitch_tap(item.key,item.address_id)">
				<image class="box_image" :src="item.is_show==0?'../../static/38.png':'../../static/37.png'"></image>
				<view class="box_text">
					<view class="box_text_name">
						<view class="box_text_name_name">收货人: {{item.name}}</view>
						<view class="box_text_phone">{{item.mobile}}</view>
					</view>
					<view class="box_text_address">{{item.province}} {{item.city}} {{item.region}} {{item.address}} </view>
				</view>
				<image class="box_images" @click.stop="compile_tap(item.address_id)" src="../../static/36.png"></image>
			</view>
			<view v-if="list.length == 0" class="zanwu">暂无更多数据</view>
		</view>
		<view class="anniu" @click="new_address">新增收货地址</view>
	</view>
</template>
<script>
	import urlConfig from '../../common/config.js';
	export default {
		data() {
			return {
				list:[],
			}
		},
		onShow() {
			if( !uni.getStorageSync('access_token') ) {
				uni.showModal({
					title: '提示',
					content: '请先登录',
					cancelText:'返回',
					confirmColor:'#A02731',
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.reLaunch({
								url:'../disembark/disembark'
							})
						} else if (res.cancel) {
							wx.closeWindow()
						}
					}
				});
			}else{
				this.address_list_api()
			}
		},
		methods: {
			address_list_api() {
				var that = this
				that.$request(that.$Api.address_list_api, {
					access_token: uni.getStorageSync('access_token'),
				}, "POST").then(res => {
					if (res.data.code == 0) {
						for( let i=0;i<res.data.data.list.length;i++ ) {
							res.data.data.list[i]['key'] = i
							res.data.data.list[i]['is_show'] = res.data.data.list[i].default
						}
						that.list = res.data.data.list
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
			default_api(address_id) {
				var that = this
				that.$request(that.$Api.address_default_api, {
					access_token: uni.getStorageSync('access_token'),
					address_id:address_id
				}, "POST").then(res => {
					uni.showToast({
						title: res.data.msg,
						duration: 2000,
						icon: 'none'
					});
				})
			},
			//新增地址
			new_address() {
				var token = uni.getStorageSync('access_token')
				// uni.navigateTo({
				// 	url:'../new_address/new_address'
				// })
				uni.navigateTo({
					url:'../amend_address/amend_address'
				})
			},
			//编辑
			compile_tap(address_id) {
				uni.navigateTo({
					url:'../amend_address/amend_address?address_id='+address_id
				})
			},
			//选中
			pitch_tap(num,address_id) {
				for(let i=0;i<this.list.length;i++) {
					if(num == this.list[i].key) {
						if( this.list[i].is_show == 1 ) {
							this.list[i].is_show = 0
						}else{
							this.list[i].is_show = 1
							this.default_api(address_id)
						}
					}else{
						this.list[i].is_show = 0
					}
				}
			},
		}
	}
</script>


















